<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>新增关键字</title>
<%@include file="../collect/meta.jsp"%>
<link rel="stylesheet" href="css/radius.css" type="text/css"></link>
<link rel="stylesheet" href="css/Inputstyle.css" type="text/css"></link>
<link rel="stylesheet" href="css/question.css" type="text/css"></link>
<script type="text/javascript" src="${ctx}/js/returnTop.js"></script>
</head>
<body lang="zh-cn">
	<div class="wrapper">
		<c:import url="/collect/top.jsp"></c:import>
		<div class="main-container" id="main-container">
			<div class="main-container-inner">
				<c:import url="/collect/left.jsp"></c:import>
				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<ul class="breadcrumb">
							<li><i class="icon-home home-icon"></i>微信管理</li>
							<li>自动回复管理</li>
							<li><a href="question!watchQuestions">设置关键字</a></li>
							<li>新增关键字</li>
						</ul>
						<!-- .breadcrumb -->
					</div>
					<div class="page-content">
						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<form action="question!addQuestion" name="addQuestion"
									method="post">
									<input type="hidden" id="eaId" value="${eaId }">
									<div align="center">
										<div class="title">
											<label for="one">关键字:&nbsp;</label> <input type="text" class="input"
												id="one" name="question.content" />
											<div id="content" class="cont"></div>
										</div>
										<div class="model" style="display: none;">
											<label>关键字模式:&nbsp;</label> 
											<select
												name="question.searchType">
												<option value="1">包含</option>
												<option value="2">精准</option>
											</select>
										</div>
										<div class="replyclass">
											<label>回复类型:&nbsp;</label>
											<select name="question.type" id="questionType">
												<option value="1">文本</option>
												<option value="2">链接</option>
												<option value="3">图文</option>
											</select>
										</div>
										<div class="replycont">
											<label>回复内容:&nbsp;</label>
											<select name="question.relyId" id="questionRely">
												<c:forEach items="${replies }" var="reply">
													<option value="${reply.id }">${reply.title }</option>
												</c:forEach>
											</select>
										</div>

										<div id="btn-team">
											<input type="button" class="btn btn-primary radius" id="but"
												value="添加" /> <a class="btn btn-primary radius"
												href="question!watchQuestions">返回</a>
										</div>
									</div>
								</form>
								<!-- PAGE CONTENT ENDS -->
							</div>
							<!-- /.col -->
						</div>
						<!-- /.row -->
					</div>
					<!-- /.page-content -->
				</div>
				<!-- /.main-content -->
			</div>
			<!-- /.main-container-inner -->
			<a href="#" id="btn-scroll-up"
				class="btn-scroll-up btn btn-sm btn-inverse"
				style="position:fixed;bottom:0;"> <i
				class="icon-double-angle-up icon-only bigger-110"></i> </a>
		</div>
		<!-- /.main-container -->
		<div class="push"></div>
	</div>
	<c:import url="/collect/down.jsp"></c:import>

	<script type="text/javascript">
		$(document)
				.ready(
						function() {

							$("select[id='questionType']")
									.change(
											function() {
												var queType = $(
														"select[id='questionType']")
														.val();
												var eaId = $("input[id='eaId']")
														.val();
												$
														.ajax({
															async : false,
															url : "question!changeReplyByType",
															type : "post",
															data : {
																"questionType" : queType,
																"eaId" : eaId
															},
															datatype : "json",
															success : function(
																	data) {
																var map = eval("("
																		+ data
																		+ ")");
																$(
																		"select[id='questionRely']")
																		.empty();
																for ( var i = 0; i < map.length; i++) {
																	$(
																			"select[id='questionRely']")
																			.append(
																					"<option value="+map[i].id+">"
																							+ map[i].title
																							+ "</option>");
																}
															},
															error : function(
																	request) {
																alert("Connection error");
															}
														});
											});

							var nu = /\s/;
							var str = /[\ |\~|\`|\@|\#|\$|\%|\^|\&|\||\\|\[|\]|\{|\}|\"|\'|\<|\>|\/]/;
							$("input[id='one']").focus(function() {
								$(this).addClass("tbinput");
								$("div[id='content']").html("");
							});
							$("input[id='one']").blur(
									function() {
										$(this).removeClass("tbinput");
										var one = $(this).val();

										if (one.length == 0) {
											$("div[id='content']")
													.html("必填").removeClass(
															"success")
													.addClass("error");
											return false;
										}

										if (!nu.test(one) && !str.test(one)) {
											$("div[id='content']")
													.html("确认").removeClass(
															"error").addClass(
															"success");
										} else {
											$("div[id='content']").html(
													"含有特殊字符").removeClass(
													"success")
													.addClass("error");
										}
									});
							$("#but").click(function() {
								var one = $("div[id='content']").text();
								var two = $("select[id='questionRely']").val();
								if (two == null || two == "") {
									alert("该回复类型还未设置，请您先在【设置回复】功能中新建好回复！");
									return false;
								}
								if (one == "确认") {
									$("form[name='addQuestion']").submit();
								} else {
									alert("请完善以上信息");
									return false;
								}
							});
						});
		//防dropmenu刷新收回;设置关键字：$新增关键字
		$(document).ready(function() {
			$('.weixinguanli > ul').show();
			$('.autoanswer > ul').show();
			$('.autoanswer > ul > li a').eq(2).css("color", "red");
		});
	</script>
</body>
</html>